﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpSoft.Library.DAO.Contents;
using MpSoft.Library.DTO;
using MpSoft.Basic.Configuration;

namespace MpSoft.Library.BUSS.Contents
{
    #region  Adv
    public class AdvBUSS
    {
        private const string ADV_ALL_KEY = "Mp.adv.all-{0}}";
        private const string ADV_BY_ID_KEY = "Mp.adv.id-{0}";

        public static int Adv_Add(Adv obj)
        {
            var result = AdvDAO.Adv_Add(obj);
            if (result > 0)
            {
                MpCache.RemoveByPattern(ADV_ALL_KEY);
                MpCache.RemoveByPattern(ADV_BY_ID_KEY);
            }
            return result;
        }
        public static int Adv_Update(Adv obj)
        {
            var result = AdvDAO.Adv_Update(obj);
            if (result > 0)
            {
                MpCache.RemoveByPattern(ADV_ALL_KEY);
                MpCache.RemoveByPattern(ADV_BY_ID_KEY);
            }
            return result;
        }

        public static int Adv_Delete(int AdvID)
        {
            var result = AdvDAO.Adv_Delete(AdvID);
            if (result > 0)
            {
                MpCache.RemoveByPattern(ADV_ALL_KEY);
                MpCache.RemoveByPattern(ADV_BY_ID_KEY);
            }
            return result;
        }

        public static Adv Adv_ByID(int AdvID)
        {
            var list = Adv_List(AdvID, -1, 1);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }

        public static List<Adv> Adv_List()
        {
            return Adv_List(-1, 0);
        }

        public static List<Adv> Adv_List(int Region, int IsActive)
        {
            return Adv_List(-1, Region, IsActive);
        }

        public static List<Adv> Adv_List(int AdvID, int Region, int IsActive)
        {
            return AdvDAO.Adv_List(AdvID, Region, IsActive);
        }
    }
    #endregion
}
